/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.kruth

import kotlin.reflect.KClass
import kotlin.test.assertFailsWith

// Commonized extensions on top of Truth. These are kept separate for book-keeping in case we end up
// promoting Kruth.

// Truth doesn't expose an assertThrows { .. }, but instead asks users to rely on the one from
// JUnit, and then wrap it into a ThrowableSubject. However, this is a common enough pattern that
// we created a helper for this in internal-testutils-truth.
//
// See: https://github.com/google/truth/issues/621
inline fun <reified T : Throwable> assertThrows(block: () -> Unit): ThrowableSubject<T> {
    val e = assertFailsWith<T>(block = block)
    return assertThat(e)
}

inline fun <T : Throwable> assertThrows(exceptionClass: KClass<T>, block: () -> Unit):
    ThrowableSubject<T> {
    val e = assertFailsWith<T>(exceptionClass = exceptionClass, block = block)
    return assertThat(e)
}
